package com.hswealth;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class DishApp {
	
	static List<Dish> dishList = new ArrayList<>();
	static List<Dish> personDish = new ArrayList<Dish>();
	
	public static void main(String[] args) {
		
		initDish();
		
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		
		while(true) {
			showMenu();
			
			int num = scanner.nextInt();
			
			switch (num) {
				case 1:
					while(true) {
						showDishMenu();
						int no = scanner.nextInt();
						if (no == 0) {
							break;
						}else if (no > dishList.size()) {
							System.out.println("您输入的序号有误，请重新输入");
						}else{
							personDish.add(dishList.get(no - 1));
							System.out.println("您点了" + dishList.get(no - 1).name);
						}
					}
				case 2:
					showPersonDish();
					break;
				case 3:
					buy();
					return;
			}
		}
		
		
		
	}
	
	private static void buy() {
		double total = 0F;
		for (int i = 0; i < personDish.size(); i++) {
			total += personDish.get(i).price;
		}
		System.out.println("您一共需要支付" + total + "元");
		
	}

	private static void initDish() {
		
		dishList.add(new Dish(1, "青椒肉丝\t", 15.0));
		dishList.add(new Dish(2, "蚂蚁上树\t", 18.0));
		dishList.add(new Dish(3, "雪菜肉丝\t", 15.0));
		dishList.add(new Dish(4, "东坡肉\t", 20.0));
		dishList.add(new Dish(5, "龙门花甲\t", 35.0));
		
	}
	
	private static void showMenu() {
		
		System.out.println("------垃圾点菜系统欢迎您------");
		System.out.println("------请选择您想要的服务------");
		System.out.println("1\t点菜");
		System.out.println("2\t查看已点菜品");
		System.out.println("3\t买单");
		System.out.println("-----请输入对应编号------");
		
	}
	
	private static void showDishMenu() {
		
		System.out.println("-----本店菜品如下-------");
		for (int i = 0; i < dishList.size(); i++) {
			Dish dish = dishList.get(i);
			System.out.println(dish.id + "\t" + dish.name + "\t" + dish.price);
		}
		System.out.println("-----请输入菜单序号，按0返回上一层-----");
	}
	
	private static void showPersonDish() {
		System.out.println("-----您已点了如下菜品-------");
		for (int i = 0; i < personDish.size(); i++) {
			Dish dish = personDish.get(i);
			System.out.println(dish.id + "\t" + dish.name + "\t" + dish.price);
		}
	}

}
